package cn.jasonone.tio.tcp.config.constants;

import java.nio.charset.Charset;
import java.util.Objects;

/**
 * @author xujie
 * @version 1.0
 * @date 2022/1/18 9:22
 */
public enum CharsetEnum {
    /**
     * Big5
     */
    Big5(0, Charset.forName("Big5")),
    /**
     * Big5-HKSCS
     */
    Big5_HKSCS(1, Charset.forName("Big5-HKSCS")),
    /**
     * CESU-8
     */
    CESU_8(2, Charset.forName("CESU-8")),
    /**
     * EUC-JP
     */
    EUC_JP(3, Charset.forName("EUC-JP")),
    /**
     * EUC-KR
     */
    EUC_KR(4, Charset.forName("EUC-KR")),
    /**
     * GB18030
     */
    GB18030(5, Charset.forName("GB18030")),
    /**
     * GB2312
     */
    GB2312(6, Charset.forName("GB2312")),
    /**
     * GBK
     */
    GBK(7, Charset.forName("GBK")),
    /**
     * IBM-Thai
     */
    IBM_Thai(8, Charset.forName("IBM-Thai")),
    /**
     * IBM00858
     */
    IBM00858(9, Charset.forName("IBM00858")),
    /**
     * IBM01140
     */
    IBM01140(10, Charset.forName("IBM01140")),
    /**
     * IBM01141
     */
    IBM01141(11, Charset.forName("IBM01141")),
    /**
     * IBM01142
     */
    IBM01142(12, Charset.forName("IBM01142")),
    /**
     * IBM01143
     */
    IBM01143(13, Charset.forName("IBM01143")),
    /**
     * IBM01144
     */
    IBM01144(14, Charset.forName("IBM01144")),
    /**
     * IBM01145
     */
    IBM01145(15, Charset.forName("IBM01145")),
    /**
     * IBM01146
     */
    IBM01146(16, Charset.forName("IBM01146")),
    /**
     * IBM01147
     */
    IBM01147(17, Charset.forName("IBM01147")),
    /**
     * IBM01148
     */
    IBM01148(18, Charset.forName("IBM01148")),
    /**
     * IBM01149
     */
    IBM01149(19, Charset.forName("IBM01149")),
    /**
     * IBM037
     */
    IBM037(20, Charset.forName("IBM037")),
    /**
     * IBM1026
     */
    IBM1026(21, Charset.forName("IBM1026")),
    /**
     * IBM1047
     */
    IBM1047(22, Charset.forName("IBM1047")),
    /**
     * IBM273
     */
    IBM273(23, Charset.forName("IBM273")),
    /**
     * IBM277
     */
    IBM277(24, Charset.forName("IBM277")),
    /**
     * IBM278
     */
    IBM278(25, Charset.forName("IBM278")),
    /**
     * IBM280
     */
    IBM280(26, Charset.forName("IBM280")),
    /**
     * IBM284
     */
    IBM284(27, Charset.forName("IBM284")),
    /**
     * IBM285
     */
    IBM285(28, Charset.forName("IBM285")),
    /**
     * IBM290
     */
    IBM290(29, Charset.forName("IBM290")),
    /**
     * IBM297
     */
    IBM297(30, Charset.forName("IBM297")),
    /**
     * IBM420
     */
    IBM420(31, Charset.forName("IBM420")),
    /**
     * IBM424
     */
    IBM424(32, Charset.forName("IBM424")),
    /**
     * IBM437
     */
    IBM437(33, Charset.forName("IBM437")),
    /**
     * IBM500
     */
    IBM500(34, Charset.forName("IBM500")),
    /**
     * IBM775
     */
    IBM775(35, Charset.forName("IBM775")),
    /**
     * IBM850
     */
    IBM850(36, Charset.forName("IBM850")),
    /**
     * IBM852
     */
    IBM852(37, Charset.forName("IBM852")),
    /**
     * IBM855
     */
    IBM855(38, Charset.forName("IBM855")),
    /**
     * IBM857
     */
    IBM857(39, Charset.forName("IBM857")),
    /**
     * IBM860
     */
    IBM860(40, Charset.forName("IBM860")),
    /**
     * IBM861
     */
    IBM861(41, Charset.forName("IBM861")),
    /**
     * IBM862
     */
    IBM862(42, Charset.forName("IBM862")),
    /**
     * IBM863
     */
    IBM863(43, Charset.forName("IBM863")),
    /**
     * IBM864
     */
    IBM864(44, Charset.forName("IBM864")),
    /**
     * IBM865
     */
    IBM865(45, Charset.forName("IBM865")),
    /**
     * IBM866
     */
    IBM866(46, Charset.forName("IBM866")),
    /**
     * IBM868
     */
    IBM868(47, Charset.forName("IBM868")),
    /**
     * IBM869
     */
    IBM869(48, Charset.forName("IBM869")),
    /**
     * IBM870
     */
    IBM870(49, Charset.forName("IBM870")),
    /**
     * IBM871
     */
    IBM871(50, Charset.forName("IBM871")),
    /**
     * IBM918
     */
    IBM918(51, Charset.forName("IBM918")),
    /**
     * ISO-2022-CN
     */
    ISO_2022_CN(52, Charset.forName("ISO-2022-CN")),
    /**
     * ISO-2022-JP
     */
    ISO_2022_JP(53, Charset.forName("ISO-2022-JP")),
    /**
     * ISO-2022-JP-2
     */
    ISO_2022_JP_2(54, Charset.forName("ISO-2022-JP-2")),
    /**
     * ISO-2022-KR
     */
    ISO_2022_KR(55, Charset.forName("ISO-2022-KR")),
    /**
     * ISO-8859-1
     */
    ISO_8859_1(56, Charset.forName("ISO-8859-1")),
    /**
     * ISO-8859-13
     */
    ISO_8859_13(57, Charset.forName("ISO-8859-13")),
    /**
     * ISO-8859-15
     */
    ISO_8859_15(58, Charset.forName("ISO-8859-15")),
    /**
     * ISO-8859-2
     */
    ISO_8859_2(59, Charset.forName("ISO-8859-2")),
    /**
     * ISO-8859-3
     */
    ISO_8859_3(60, Charset.forName("ISO-8859-3")),
    /**
     * ISO-8859-4
     */
    ISO_8859_4(61, Charset.forName("ISO-8859-4")),
    /**
     * ISO-8859-5
     */
    ISO_8859_5(62, Charset.forName("ISO-8859-5")),
    /**
     * ISO-8859-6
     */
    ISO_8859_6(63, Charset.forName("ISO-8859-6")),
    /**
     * ISO-8859-7
     */
    ISO_8859_7(64, Charset.forName("ISO-8859-7")),
    /**
     * ISO-8859-8
     */
    ISO_8859_8(65, Charset.forName("ISO-8859-8")),
    /**
     * ISO-8859-9
     */
    ISO_8859_9(66, Charset.forName("ISO-8859-9")),
    /**
     * JIS_X0201
     */
    JIS_X0201(67, Charset.forName("JIS_X0201")),
    /**
     * JIS_X0212-1990
     */
    JIS_X0212_1990(68, Charset.forName("JIS_X0212-1990")),
    /**
     * KOI8-R
     */
    KOI8_R(69, Charset.forName("KOI8-R")),
    /**
     * KOI8-U
     */
    KOI8_U(70, Charset.forName("KOI8-U")),
    /**
     * Shift_JIS
     */
    Shift_JIS(71, Charset.forName("Shift_JIS")),
    /**
     * TIS-620
     */
    TIS_620(72, Charset.forName("TIS-620")),
    /**
     * US-ASCII
     */
    US_ASCII(73, Charset.forName("US-ASCII")),
    /**
     * UTF-16
     */
    UTF_16(74, Charset.forName("UTF-16")),
    /**
     * UTF-16BE
     */
    UTF_16BE(75, Charset.forName("UTF-16BE")),
    /**
     * UTF-16LE
     */
    UTF_16LE(76, Charset.forName("UTF-16LE")),
    /**
     * UTF-32
     */
    UTF_32(77, Charset.forName("UTF-32")),
    /**
     * UTF-32BE
     */
    UTF_32BE(78, Charset.forName("UTF-32BE")),
    /**
     * UTF-32LE
     */
    UTF_32LE(79, Charset.forName("UTF-32LE")),
    /**
     * UTF-8
     */
    UTF_8(80, Charset.forName("UTF-8")),
    /**
     * windows-1250
     */
    windows_1250(81, Charset.forName("windows-1250")),
    /**
     * windows-1251
     */
    windows_1251(82, Charset.forName("windows-1251")),
    /**
     * windows-1252
     */
    windows_1252(83, Charset.forName("windows-1252")),
    /**
     * windows-1253
     */
    windows_1253(84, Charset.forName("windows-1253")),
    /**
     * windows-1254
     */
    windows_1254(85, Charset.forName("windows-1254")),
    /**
     * windows-1255
     */
    windows_1255(86, Charset.forName("windows-1255")),
    /**
     * windows-1256
     */
    windows_1256(87, Charset.forName("windows-1256")),
    /**
     * windows-1257
     */
    windows_1257(88, Charset.forName("windows-1257")),
    /**
     * windows-1258
     */
    windows_1258(89, Charset.forName("windows-1258")),
    /**
     * windows-31j
     */
    windows_31j(90, Charset.forName("windows-31j")),
    /**
     * x-Big5-HKSCS-2001
     */
    x_Big5_HKSCS_2001(91, Charset.forName("x-Big5-HKSCS-2001")),
    /**
     * x-Big5-Solaris
     */
    x_Big5_Solaris(92, Charset.forName("x-Big5-Solaris")),
    /**
     * x-euc-jp-linux
     */
    x_euc_jp_linux(93, Charset.forName("x-euc-jp-linux")),
    /**
     * x-EUC-TW
     */
    x_EUC_TW(94, Charset.forName("x-EUC-TW")),
    /**
     * x-eucJP-Open
     */
    x_eucJP_Open(95, Charset.forName("x-eucJP-Open")),
    /**
     * x-IBM1006
     */
    x_IBM1006(96, Charset.forName("x-IBM1006")),
    /**
     * x-IBM1025
     */
    x_IBM1025(97, Charset.forName("x-IBM1025")),
    /**
     * x-IBM1046
     */
    x_IBM1046(98, Charset.forName("x-IBM1046")),
    /**
     * x-IBM1097
     */
    x_IBM1097(99, Charset.forName("x-IBM1097")),
    /**
     * x-IBM1098
     */
    x_IBM1098(100, Charset.forName("x-IBM1098")),
    /**
     * x-IBM1112
     */
    x_IBM1112(101, Charset.forName("x-IBM1112")),
    /**
     * x-IBM1122
     */
    x_IBM1122(102, Charset.forName("x-IBM1122")),
    /**
     * x-IBM1123
     */
    x_IBM1123(103, Charset.forName("x-IBM1123")),
    /**
     * x-IBM1124
     */
    x_IBM1124(104, Charset.forName("x-IBM1124")),
    /**
     * x-IBM1166
     */
    x_IBM1166(105, Charset.forName("x-IBM1166")),
    /**
     * x-IBM1364
     */
    x_IBM1364(106, Charset.forName("x-IBM1364")),
    /**
     * x-IBM1381
     */
    x_IBM1381(107, Charset.forName("x-IBM1381")),
    /**
     * x-IBM1383
     */
    x_IBM1383(108, Charset.forName("x-IBM1383")),
    /**
     * x-IBM300
     */
    x_IBM300(109, Charset.forName("x-IBM300")),
    /**
     * x-IBM33722
     */
    x_IBM33722(110, Charset.forName("x-IBM33722")),
    /**
     * x-IBM737
     */
    x_IBM737(111, Charset.forName("x-IBM737")),
    /**
     * x-IBM833
     */
    x_IBM833(112, Charset.forName("x-IBM833")),
    /**
     * x-IBM834
     */
    x_IBM834(113, Charset.forName("x-IBM834")),
    /**
     * x-IBM856
     */
    x_IBM856(114, Charset.forName("x-IBM856")),
    /**
     * x-IBM874
     */
    x_IBM874(115, Charset.forName("x-IBM874")),
    /**
     * x-IBM875
     */
    x_IBM875(116, Charset.forName("x-IBM875")),
    /**
     * x-IBM921
     */
    x_IBM921(117, Charset.forName("x-IBM921")),
    /**
     * x-IBM922
     */
    x_IBM922(118, Charset.forName("x-IBM922")),
    /**
     * x-IBM930
     */
    x_IBM930(119, Charset.forName("x-IBM930")),
    /**
     * x-IBM933
     */
    x_IBM933(120, Charset.forName("x-IBM933")),
    /**
     * x-IBM935
     */
    x_IBM935(121, Charset.forName("x-IBM935")),
    /**
     * x-IBM937
     */
    x_IBM937(122, Charset.forName("x-IBM937")),
    /**
     * x-IBM939
     */
    x_IBM939(123, Charset.forName("x-IBM939")),
    /**
     * x-IBM942
     */
    x_IBM942(124, Charset.forName("x-IBM942")),
    /**
     * x-IBM942C
     */
    x_IBM942C(125, Charset.forName("x-IBM942C")),
    /**
     * x-IBM943
     */
    x_IBM943(126, Charset.forName("x-IBM943")),
    /**
     * x-IBM943C
     */
    x_IBM943C(127, Charset.forName("x-IBM943C")),
    /**
     * x-IBM948
     */
    x_IBM948(128, Charset.forName("x-IBM948")),
    /**
     * x-IBM949
     */
    x_IBM949(129, Charset.forName("x-IBM949")),
    /**
     * x-IBM949C
     */
    x_IBM949C(130, Charset.forName("x-IBM949C")),
    /**
     * x-IBM950
     */
    x_IBM950(131, Charset.forName("x-IBM950")),
    /**
     * x-IBM964
     */
    x_IBM964(132, Charset.forName("x-IBM964")),
    /**
     * x-IBM970
     */
    x_IBM970(133, Charset.forName("x-IBM970")),
    /**
     * x-ISCII91
     */
    x_ISCII91(134, Charset.forName("x-ISCII91")),
    /**
     * x-ISO-2022-CN-CNS
     */
    x_ISO_2022_CN_CNS(135, Charset.forName("x-ISO-2022-CN-CNS")),
    /**
     * x-ISO-2022-CN-GB
     */
    x_ISO_2022_CN_GB(136, Charset.forName("x-ISO-2022-CN-GB")),
    /**
     * x-iso-8859-11
     */
    x_iso_8859_11(137, Charset.forName("x-iso-8859-11")),
    /**
     * x-JIS0208
     */
    x_JIS0208(138, Charset.forName("x-JIS0208")),
    /**
     * x-JISAutoDetect
     */
    x_JISAutoDetect(139, Charset.forName("x-JISAutoDetect")),
    /**
     * x-Johab
     */
    x_Johab(140, Charset.forName("x-Johab")),
    /**
     * x-MacArabic
     */
    x_MacArabic(141, Charset.forName("x-MacArabic")),
    /**
     * x-MacCentralEurope
     */
    x_MacCentralEurope(142, Charset.forName("x-MacCentralEurope")),
    /**
     * x-MacCroatian
     */
    x_MacCroatian(143, Charset.forName("x-MacCroatian")),
    /**
     * x-MacCyrillic
     */
    x_MacCyrillic(144, Charset.forName("x-MacCyrillic")),
    /**
     * x-MacDingbat
     */
    x_MacDingbat(145, Charset.forName("x-MacDingbat")),
    /**
     * x-MacGreek
     */
    x_MacGreek(146, Charset.forName("x-MacGreek")),
    /**
     * x-MacHebrew
     */
    x_MacHebrew(147, Charset.forName("x-MacHebrew")),
    /**
     * x-MacIceland
     */
    x_MacIceland(148, Charset.forName("x-MacIceland")),
    /**
     * x-MacRoman
     */
    x_MacRoman(149, Charset.forName("x-MacRoman")),
    /**
     * x-MacRomania
     */
    x_MacRomania(150, Charset.forName("x-MacRomania")),
    /**
     * x-MacSymbol
     */
    x_MacSymbol(151, Charset.forName("x-MacSymbol")),
    /**
     * x-MacThai
     */
    x_MacThai(152, Charset.forName("x-MacThai")),
    /**
     * x-MacTurkish
     */
    x_MacTurkish(153, Charset.forName("x-MacTurkish")),
    /**
     * x-MacUkraine
     */
    x_MacUkraine(154, Charset.forName("x-MacUkraine")),
    /**
     * x-MS932_0213
     */
    x_MS932_0213(155, Charset.forName("x-MS932_0213")),
    /**
     * x-MS950-HKSCS
     */
    x_MS950_HKSCS(156, Charset.forName("x-MS950-HKSCS")),
    /**
     * x-MS950-HKSCS-XP
     */
    x_MS950_HKSCS_XP(157, Charset.forName("x-MS950-HKSCS-XP")),
    /**
     * x-mswin-936
     */
    x_mswin_936(158, Charset.forName("x-mswin-936")),
    /**
     * x-PCK
     */
    x_PCK(159, Charset.forName("x-PCK")),
    /**
     * x-SJIS_0213
     */
    x_SJIS_0213(160, Charset.forName("x-SJIS_0213")),
    /**
     * x-UTF-16LE-BOM
     */
    x_UTF_16LE_BOM(161, Charset.forName("x-UTF-16LE-BOM")),
    /**
     * X-UTF-32BE-BOM
     */
    X_UTF_32BE_BOM(162, Charset.forName("X-UTF-32BE-BOM")),
    /**
     * X-UTF-32LE-BOM
     */
    X_UTF_32LE_BOM(163, Charset.forName("X-UTF-32LE-BOM")),
    /**
     * x-windows-50220
     */
    x_windows_50220(164, Charset.forName("x-windows-50220")),
    /**
     * x-windows-50221
     */
    x_windows_50221(165, Charset.forName("x-windows-50221")),
    /**
     * x-windows-874
     */
    x_windows_874(166, Charset.forName("x-windows-874")),
    /**
     * x-windows-949
     */
    x_windows_949(167, Charset.forName("x-windows-949")),
    /**
     * x-windows-950
     */
    x_windows_950(168, Charset.forName("x-windows-950")),
    /**
     * x-windows-iso2022jp
     */
    x_windows_iso2022jp(169, Charset.forName("x-windows-iso2022jp"));
    private byte code;
    private Charset charset;

    CharsetEnum(int code, Charset charset) {
        this.code = (byte) code;
        this.charset = charset;
    }

    public byte getCode() {
        return code;
    }

    public Charset getCharset() {
        return charset;
    }

    public static CharsetEnum valueOf(Charset charset) {
        for (CharsetEnum charsetEnum : values()) {
            if (Objects.equals(charsetEnum.charset.name(), charset.name())) {
                return charsetEnum;
            }
        }
        return null;
    }

    public static CharsetEnum valueOf(byte charsetCode) {
        for (CharsetEnum charsetEnum : values()) {
            if (Objects.equals(charsetEnum.code, charsetCode)) {
                return charsetEnum;
            }
        }
        return null;
    }
}
